<?php

require '../vendor/autoload.php';

use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\Marshaler;

$sdk = new Aws\Sdk([
    'region'   => 'us-west-2',
    'version'  => 'latest',
    'credentials' => [
        'key' => 'AKIA4SBKFCJAXUOUXUN2',
        'secret' => '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',
    ],
]);

$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();


//插入50条随机数据
for ($i = 0; $i < 50; $i++) {
    $group_id=mt_rand(1,4);
    $user_id = mt_rand(1,999999999);
    $create_time = time() + mt_rand(300, 10 * 24 * 60 * 60);

    $item = $marshaler->marshalItem([
        'group_id' => $group_id,
        'user_id' => $user_id,
        'create_time' => $create_time,
    ]);

    $params = [
        'TableName' => 'group',
        'Item' => $item,
    ];

    try {
        $result = $dynamodb->putItem($params);
        echo "Added item success" . PHP_EOL;
    } catch (DynamoDbException $e) {
        echo "Unable to add item:\n";
        echo $e->getMessage() . "\n";
    }
}
